{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0B05"
test("0B05 (copy_directory)", tests)
terminate_this_custom_script


const Test_Path_Src = "cleo\cleo_test_dir"
const Test_Path_Dst = "test_directory"

function tests
    before_each(@cleanup)
    after_each(@cleanup)

    it("should fail on a non-existing directory", test1)
    it("should move directory", test2)
    return
    
    :cleanup
        set_current_directory {path} 0
        delete_directory {path} Test_Path_Src {recursive} true
        delete_directory {path} Test_Path_Dst {recursive} true
    return
    
    function test1
        does_directory_exist {dirPath} Test_Path_Src
        assert_result_false()
        
        copy_directory {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
        assert_result_false()
    end
    
    function test2        
        // setup
        create_directory {path} Test_Path_Src
        set_current_directory {path} Test_Path_Src
        create_directory {path} "Test_Sub_Dir"
        write_int_to_ini_file {value} 42 {path} "Test_File.ini" {section} "test" {key} "test"
        set_current_directory {path} 0
        assert_result_true()
        does_directory_exist {dirPath} Test_Path_Src
        assert_result_true()
        does_directory_exist {dirPath} Test_Path_Dst
        assert_result_false()
        
        // check if file was actually created in desired location
        int str = allocate_memory {size} 260
        string_format str = "%s\\Test_File.ini" Test_Path_Src
        int value = read_int_from_ini_file {path} str {section} "test" {key} "test"
        assert_eq(value, 42)
        free_memory str
    
        // act
        copy_directory {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
        assert_result_true()
        does_directory_exist {dirPath} Test_Path_Src
        assert_result_true()
        does_directory_exist {dirPath} Test_Path_Dst
        assert_result_true()
        
        // check contents
        set_current_directory {path} Test_Path_Src
        does_directory_exist {path} "Test_Sub_Dir"
        assert_result_true()
        value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
        assert_eq(value, 42)
        set_current_directory {path} 0
        
        set_current_directory {path} Test_Path_Dst
        does_directory_exist {path} "Test_Sub_Dir"
        assert_result_true()
        value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
        assert_eq(value, 42)
    end

end
